package com.youzikj.wx.pay;

import java.util.HashMap;
import java.util.Map;

import com.youzikj.wx.comm.util.CommonUtil;
import com.youzikj.wx.pay.hongbao.MoneyUtils;

/**
 * 微信公众号-支付类
 * @author Administrator
 *
 */
public class WxPay{
	
	public static String sendPay(int price,String openid){
	
		String mch_billno = MoneyUtils.getMch_billno();
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("appid", "wxca78deeb014de180"); //公众账号ID
		map.put("mch_id", 1419995602);    //商户号
		map.put("nonce_str", MoneyUtils.buildRandom()); //随机字符串
		map.put("body", "微友传单");   //商品描述
		map.put("out_trade_no", mch_billno);  //商户订单号
		map.put("total_fee", price);    //金额   单位分
		map.put("spbill_create_ip", Configure.getIp());  //终端IP
		map.put("notify_url", Configure.getNotifyCallbackUrl());
		map.put("trade_type", "JSAPI");
		map.put("openid", openid);
		map.put("sign", MoneyUtils.createSign(map));//签名
		
		String result = "";
		try {
			result = MoneyUtils.doSendMoney(Configure.PAY_API, MoneyUtils.createXML(map));
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("result:"+result);
		//result_code SUCCESS 代表成功
		return result;
	}
}

